from django.db import models


class User(models.Model):
    """用户表"""
    id = models.BigAutoField(verbose_name="ID", primary_key=True)
    username = models.CharField(verbose_name="用户名", max_length=30)  # varchar(32)
    password = models.CharField(verbose_name="密码", max_length=30)  # varchar(32)


class Department(models.Model):
    """院系表"""
    id = models.BigAutoField(verbose_name="ID", primary_key=True)
    title = models.CharField(verbose_name="院系名", max_length=32)

    def __str__(self):
        return self.title


class Student(models.Model):
    """学生表"""
    id = models.BigIntegerField(verbose_name="学号", primary_key=True)
    name = models.CharField(verbose_name="姓名", max_length=15)
    age = models.IntegerField(verbose_name="年龄")

    address = models.CharField(verbose_name="住址", max_length=50)
    account = models.DecimalField(verbose_name="校园卡余额", max_digits=10, decimal_places=2, default=0)
    time = models.DateTimeField(verbose_name="注册时间")
    # 外键，删除置NULL
    depart = models.ForeignKey(verbose_name="所属院系", to="Department", to_field="id", null=True, blank=True, on_delete=models.SET_NULL)

    # 在Django做的约束
    gender_choices = (
        (1, "男"),
        (2, "女"),
    )
    gender = models.SmallIntegerField(verbose_name="性别", choices=gender_choices)
